package com.zrrd._01_servlet.mapper;

import java.sql.*;

/**
 * @author WanJl
 * @version 1.0
 * @title UserMapper
 * @description
 * @create 2024/1/13 10:44
 */
public class UserMapper {

    public boolean login(String uname,String pwd) throws ClassNotFoundException, SQLException {
        boolean flag=false;
        //1.加载驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        //2.建立连接
        Connection conn =
                DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/jms2301_db01",
                        "root", "123456");
        //4.编写sql语句
        String sql="SELECT * FROM jms2301_db01.user WHERE username=? AND password=?";
        //3.创建Statement对象
        PreparedStatement pstat = conn.prepareStatement(sql);
        pstat.setString(1,uname);
        pstat.setString(2,pwd);
        //5.执行sql
        ResultSet rs = pstat.executeQuery();
        //6.处理结果
        if (rs.next()){
            flag=true;
        }
        //7.释放资源
        rs.close();
        pstat.close();
        conn.close();

        return flag;
    }
}
